package com.ruoyi.web.controller.material;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.material.MaterialGrouping;
import com.ruoyi.system.service.IMaterialGroupingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * @author GE-LV5
 * @create 2023/3/6 11:16
 * 物料分组
 */
@Api(tags = "物料分组")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/material/grouping")
public class MaterialGroupingController  extends BaseController {
    @Autowired
    IMaterialGroupingService iMaterialGroupingService;

    /**
     * 查询物料分组列表
     */
    @ApiOperation(value = "查询物料分组列表")
    @PostMapping("/list")
    public TableDataInfo list(MaterialGrouping baseTeam)
    {
        startPage();
        LambdaQueryWrapper<MaterialGrouping> lqw = new LambdaQueryWrapper<MaterialGrouping>();
        if (StringUtils.isNotBlank(baseTeam.getMaterialGroupingCode())){
            lqw.eq(MaterialGrouping::getMaterialGroupingCode ,baseTeam.getMaterialGroupingCode());
        }
        if (StringUtils.isNotBlank(baseTeam.getMaterialGroupingDescribe())){
            lqw.eq(MaterialGrouping::getMaterialGroupingDescribe ,baseTeam.getMaterialGroupingDescribe());
        }
        List<MaterialGrouping> list = iMaterialGroupingService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 新增物料分组
     */
    @Log(title = "物料分组" , businessType = BusinessType.INSERT)
    @ApiOperation(value = "新增物料分组")
    @PostMapping
    public AjaxResult add(@RequestBody MaterialGrouping baseTeam) {
        return toAjax(iMaterialGroupingService.save(baseTeam) ? 1 : 0);
    }

    /**
     * 修改物料分组
     */
    @Log(title = "物料分组" , businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改物料分组")
    @PutMapping
    public AjaxResult edit(@RequestBody MaterialGrouping baseTeam) {
        return toAjax(iMaterialGroupingService.updateById(baseTeam) ? 1 : 0);
    }

    /**
     * 删除物料分组
     */
    @Log(title = "物料分组" , businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除物料分组")
    @DeleteMapping("/{teamIds}" )
    public AjaxResult remove(@PathVariable Long[] teamIds) {
        return toAjax(iMaterialGroupingService.removeByIds(Arrays.asList(teamIds)) ? 1 : 0);
    }
}
